<?php

/**
 * Description of Adresse
 *
 * @author GILLES
 */
class Application_Form_SubForm_Adresse extends Zend_Form {

    public function init() {

        // $breakChainOnFailure : true/false arrete la propogation des erreurs pour l'element
        //->addValidator($validator, $breakChainOnFailure) 

        $this->setDecorators(array('FormElements', 'Form'));
        $this->setElementsBelongTo("Adresse");

        $id_adresse = new Zend_Form_Element_Hidden('id_adresse');
        $id_adresse->addFilter('Int')
                ->addFilter('Null')
                ->setDecorators(array('ViewHelper'));

        $adresse = new Zend_Form_Element_Text('adresse');
        $adresse->setlabel('Adresse')
                ->setRequired(true)
                ->addFilter('StringTrim')
                ->addValidator('StringLength', true, array('max' => 38))
                ->setAttrib('class', 'xlarge')
                ->addValidator('NotEmpty');

        $adresse2 = new Zend_Form_Element_Text('adresse_2');
        $adresse2->setlabel('Adresse suite')
                ->addFilters(array('Null', 'StringTrim'))
                ->addValidator('StringLength', true, array('max' => 38))
                ->setAttrib('class', 'xlarge');

        $codePostal = new Zend_Form_Element_Text('cpostal');
        $codePostal->setlabel('Code Postal')
                ->setRequired(true)
                ->addValidator('PostCode', true, array('locale'=>'fr_FR'))
                //->addValidator('regex', true, array('/^[0-9\s]{5}/'))
                ->addErrorMessage('Code Postal invalide !')
                ->addFilter('StringTrim')
                ->addValidator('StringLength', true, array('max' => 5))
                ->setAttrib('class', 'span2');

        $ville = new Zend_Form_Element_Text('ville');
        $ville->setlabel('Ville')
                ->setRequired(true)
                ->addFilter('StringTrim')
                ->setAttrib('class', 'xlarge')
                ->addValidator('StringLength', true, array('max' => 38))
                ->addValidator('NotEmpty');

        $portable = new Zend_Form_Element_Text('portable');
        $portable->setlabel('Portable')
                ->addValidator('regex', true, array('/^[0-9\s]{10,14}/'))
                ->addValidator('StringLength', true, array('max' => 15))
                ->addErrorMessage('Nr de portable invalide !')
                ->setRequired(false)
                ->addFilters(array('Null', 'StringTrim'))
                ->setAttrib('class', 'span3');

        $tel = new Zend_Form_Element_Text('tel');
        $tel->setlabel('Téléphone fixe')
                ->addValidator('regex', true, array('/^[0-9\s]{10,14}/'))
                ->addValidator('StringLength', true, array('max' => 15))
                ->addErrorMessage('Nr de Téléphone invalide !')
                ->setRequired(false)
                ->addFilters(array('Null', 'StringTrim'))
                ->setAttrib('class', 'span3');

        $fax = new Zend_Form_Element_Text('fax');
        $fax->setlabel('Fax')
                ->addValidator('regex', true, array('/^[0-9\s]{10,14}/'))
                ->addValidator('StringLength', true, array('max' => 15))
                ->addErrorMessage('Nr de Fax invalide !')
                ->setRequired(false)
                ->addFilters(array('Null', 'StringTrim'))
                ->setAttrib('class', 'span3');

        $this->addElements(array($id_adresse, $adresse, $adresse2, $ville, $codePostal, $portable, $tel, $fax));
    }

}

